package LeetCode刷题.暑假刷的算法;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2021-07-19 11:15
 * @description: Functions of this class is 在一个数组中找出四个数字，其中两两相加相等a+b=c+d
 **/
public class 两数之和相等 {
    private static class Node{
        int first;
        int end;
        public Node(int first,int end){
            this.first=first;
            this.end=end;
        }
    }
    public static void main(String args[]){
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int nums[]=new int[n];
            for(int i=0;i<n;i++){
                nums[i]=scanner.nextInt();
            }
            findAdd(nums);
        }
    }
    private static void findAdd(int nums[]){
        HashMap<Integer,Node> map=new HashMap<>();
        for(int i=0;i<nums.length-1;i++){
            for(int j=i+1;j<nums.length;j++){
                if(map.containsKey(nums[i]+nums[j])){//如果发现里面存在有当前i+j的和了，即将答案输出
                    Node node=map.get(nums[i]+nums[j]);
                    System.out.println("答案："+nums[i]+"+"+nums[j]+"="+nums[node.first]+ "+" +nums[node.end]);
                    continue;
                }
                map.put(nums[i]+nums[j],new Node(i,j));
            }
        }
    }
}